#include "TimerMS.h"

TimerMS::TimerMS()
{
	m_currentTimeMS = 0;
	m_ticksPreviousFrame = (unsigned int)GetTickCount();
	m_dtMS = 0;
}

//void TimerMS::Work()
//{
//	while(true)
//	{
//		UpdateTime();
//	}
//}

void TimerMS::UpdateTime()
{
	MutexLocker ml(&m_mutex);
	unsigned int ticksCurrentFrame = (unsigned int)GetTickCount();
	unsigned int diff = ticksCurrentFrame - m_ticksPreviousFrame;

	m_dtMS = (unsigned int)diff;

	m_ticksPreviousFrame = ticksCurrentFrame;

	m_currentTimeMS += m_dtMS;

	 //       static DWORD dwTimeStart = 0;
  //      DWORD dwTimeCur = GetTickCount();
  //      if( dwTimeStart == 0 )
  //          dwTimeStart = dwTimeCur;

		//static float curTime = 0;
  //      curTime = ( dwTimeCur - dwTimeStart ) / 1000.0f;

}

void TimerMS::SetTimeMS(unsigned int ms)
{
	m_currentTimeMS = ms;
}

unsigned int TimerMS::GetTimeMS() const
{
	return m_currentTimeMS;
}

unsigned int TimerMS::GetDtMS() const
{
	return m_dtMS;
}